<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="<%=basePath%>css/ls3.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath%>images/skin.css" rel="stylesheet"
	type="text/css" />
<script type="text/javascript" src="<%=basePath%>js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
	//计算文本框字的个数
	function countChar(textareaName,spanName){  
 			document.getElementById(spanName).innerHTML = document.getElementById(textareaName).value.length;
		}  
	
	$(document).ready(function(){
		// 设置各按钮状态（是否可用）
        setButtonState();
        $("#numbers").html($.trim($("#remark").val()).length);
        
		var state = $('#state').val()+'';
		
		
	      function setButtonState() {
	    		if(state==='true'){
	    			
	    			$("#docQualityScore").attr("disabled","disabled");
	    			$("#achievementLevel").attr("disabled","disabled");
	    			$("#remark").attr("disabled","disabled");
	    			$('#temporary').attr("disabled","disabled");
	    			$('#save').attr("disabled","disabled");
	    			$('#toRemarkTemplate').attr("disabled","disabled");
	    			$("#remarkTemplate").attr("disabled","disabled");
	    			$("#cancel").attr("disabled","disabled");
	    		} else {
	                if (isValidate()) {
	                    $("#save").removeAttr("disabled");
	                } else {
	                    $("#save").attr("disabled", "disabled");
	                }
	            }
	        }
	        
	        function isValidate() {
	            
	        
	            var isValidate = true;
	            
	            var s1 = parseInt($("#docQualityScore").val());
				var s2 = parseInt($("#achievementLevel").val());
				var s3 = parseInt($("#remarkTemplate").val());
	          
	                if (s1 < 0 || s2 < 0 || s3 < 0) {
	                	isValidate = false;
	                }
	           
	            
	            
	            if($.trim($("#remark").val()).length < 20) {
	            	isValidate = false;
	            }
	            
	            return isValidate;
	        }
	        
		$("#docQualityScore").change(function(){
			total();
			
		});
		$("#achievementLevel").change(function(){
			total();
			
		});
		
		total();
		
		function total(){
			var s1 = parseInt($("#docQualityScore").val());
			var s2 = parseInt($("#achievementLevel").val());
			
			var t = 0;
			if(s1<0 && s2<0){
				
			}else{
				t = s1+s2;
				if(t<0){
					t = t+100;
				}
				
			}
			setButtonState();
			$('#total').val(t+"");
			
		}
		
		$('#temporary').click(function(){
			$('#rpForm').attr("action","../../review/temporary.html");
			$('#rpForm').submit();
		});
		$('#save').click(function(){
			var total = parseInt($('#total').val());
			var value = $('#remark').val();
			if(total<=0){
				alert("请确认该生得分");
			}else if(value.length<=0){
				alert("评阅意见不能为空");
			}else{
			
				$('#rpForm').attr("action","../../review/save.html");
				$('#rpForm').submit();
			}
		});
		$('#toExcel').click(function(){
			var url = "../../review/excel/"+$('#projectId').val()+".html";
			window.open(url);
		});
		$('#toRemarkTemplate').click(function(){
			var value = $('#remark').val();
			if(value.length<20){
				alert("评阅意见小于20");
			}else{
				var isOK = false;
				var isDuplicated = false;
				var str = window.prompt("关键字","评阅人评语-优秀");
				var description = $.trim($("#remark").val());
				if(str){
					 $.ajax({
		                    url: '../../review/getRemarkTemplateByKeyword.html',
		                    data: { 'keyword': str},
		                    dataType: 'json',
		                    type:'POST',
		                    
		                }).done(function(data){
		                	console.log(data);
		                	isDuplicated = data.isDuplicated;
		             
		                	if(isDuplicated){
		                		isOK = confirm("您输入的关键字已经存在，是否替换模板？\r\n点击确定直接替换，点击取消后修改关键字。");
		                		if(isOK){
		                			 $.ajax({
		     		                    url: '../../review/saveToTemplate.html',
		     		                    data: {'keyword': str,'description':description},
		     		                    dataType: 'json',
		     		                    type:'POST',
		     		                   success: function(data) {
		     		                        alert("保存成功!");
		     		                    }
		     		                });
		                		}
		                	}else{
		                		$.ajax({
	     		                    url: '../../review/saveToTemplate.html',
	     		                    data: { 'keyword': str,'description':description},
	     		                    dataType: 'json',
	     		                    type:'POST',
	     		                   success: function(data) {
	     		                        alert("保存成功!");
	     		                    }
	     		                });
		                	}
		                });
				}
			}
		});
		
		
		$("#remarkTemplate").change(function() {
            $.ajax({
                url: '../../mySysRemarkTemplate/findById.html',
                data: {id: $(this).val()},
                dataType: 'json',
                success: function(data) {
                    $("#remark").val(data.description);
                    setButtonState();
                    $("#numbers").html($.trim($("#remark").val()).length);
                }
            }).fail(function() {
                $("#remark").val("");
                setButtonState();
                $("#numbers").html($.trim($("#remark").val()).length);
            });
        });
		
		 // IE10中可以不用这个，其他版本求测试，先保留
        document.getElementById("remark").onpropertychange = function() {
            setButtonState();
            $("#numbers").html($.trim($("#remark").val()).length);
        };
        
        if (window.addEventListerner) {
            document.getElementById("remark").addEventListener('input', function() {
                setButtonState();
                $("#numbers").html($.trim($("#remark").val()).length);
            });
        }
	});

</script>
<title>论文评阅</title>
</head>
<body>

	<div id="contain2">
		<table width="100%" border="0" cellpadding="0" cellspacing="0"
			class="tab1">
			<tr>
				<td width="17" valign="top"
					background="<%=basePath%>images/mail_leftbg.gif"><img
					src="<%=basePath%>images/left-top-right.gif" width="17" height="29" /></td>
				<td valign="top" background="<%=basePath%>images/content-bg.gif">
					<table width="100%" height="31" border="0" cellpadding="0"
						cellspacing="0" class="left_topbg" id="table2">
						<tr>
							<td height="31"><div class="titlebt">
									<p>评阅老师评审表</p>
								</div></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>

		<div id="main">
			<div class="main1">
				<p>山&nbsp;东&nbsp;建&nbsp;筑&nbsp;大&nbsp;学&nbsp;毕&nbsp;业&nbsp;论&nbsp;文&nbsp;（&nbsp;设&nbsp;计&nbsp;）&nbsp;评&nbsp;阅&nbsp;人&nbsp;评&nbsp;审&nbsp;表</p>
			</div>
			<div class="main2">
				<p>基本信息</p>
			</div>
			<div class="main3">
				<div class="bt22">
					<p>题目名称</p>
				</div>
				<div class="bt33">
					<p>学生姓名</p>
				</div>
				<div class="bt44">
					<p>班级</p>
				</div>
				<div class="bt55">
					<p>学号</p>
				</div>
			</div>
			<div class="main3">
				<div class="bt22">
					<p>${reviewProject.project.title}</p>
				</div>
				<div class="bt33">
					<p>${reviewProject.project.student.name}</p>
				</div>
				<div class="bt44">
					<p>${reviewProject.project.student.studentClass.description}</p>
				</div>
				<div class="bt55">
					<p>${reviewProject.project.student.no}</p>
				</div>
			</div>

			<c:url var="temporaryAction" value="/review/temporary" />
			<c:url var="saveAction" value="/review/save" />
			<form:form modelAttribute="reviewProject" action="" method="post"
				name="rpForm" id="rpForm">
				<div class="main2">
					<p>评阅教师评分（每项各占10分，总计20分）</p>
				</div>
				<div class="main6">
					<div class="bt80">
							<p>
								设计（论文）质量评分（正确性、条理性、规范性、合理性、清晰、工作量）
							</p>
					</div>
					
					<div class="bt80">
						<p>
							成果的技术水平（实用性和创新性）
						</p>
					</div>
					
					<div class="bt81">
						<p>
							总计
						</p>
					</div>
				</div>
				<div class="main6">
				
					<div class="bt80">
						<p>
							<form:select id="docQualityScore" path="docQualityScore" align="center">
								<option value="-100">-打分-</option>
								<option value="10">10</option>
								<option value="9">9</option>
								<option value="8">8</option>
								<option value="7">7</option>
								<option value="6">6</option>
								<option value="5">5</option>
								<option value="4">4</option>
								<option value="3">3</option>
								<option value="2">2</option>
								<option value="1">1</option>
								<option value="0">0</option>
							</form:select>
							<span>
								<c:if test="${reviewProject.docQualityScore>=0}">
									<script type="text/javascript">
										var value = ${reviewProject.docQualityScore};
										$('#docQualityScore option[value='+value+']').attr("selected","selected");
									</script>
								</c:if>
							</span>
						</p>
					</div>
					<div class="bt80">
						<p>
							<form:select id="achievementLevel" path="achievementLevel">
								<option value="-100">-打分-</option>
								<option value="10">10</option>
								<option value="9">9</option>
								<option value="8">8</option>
								<option value="7">7</option>
								<option value="6">6</option>
								<option value="5">5</option>
								<option value="4">4</option>
								<option value="3">3</option>
								<option value="2">2</option>
								<option value="1">1</option>
								<option value="0">0</option>
							</form:select>
							<span>
								<c:choose>
									<c:when test="${reviewProject.achievementLevel>=0}">
									<script type="text/javascript">
										var value = ${reviewProject.achievementLevel};
										$('#achievementLevel option[value='+value+']').attr("selected","selected");
									</script>
									</c:when>
									<c:otherwise>
								
									</c:otherwise>
								</c:choose>
							</span>
						</p>
					</div>
					<div class="bt81">
						<p>
							<input type="text" readonly="readonly" value="0" align="middle" size="2" id="total"/>
							<script type="text/javascript">
										var value = ${reviewProject.achievementLevel};
										var value2 = ${reviewProject.docQualityScore};
										var v = parseInt(value)+parseInt(value2);
										$('#total').val(v+'');
									</script>
						</p>
					</div>
					
					
				</div>
				<div class="main2">
					<p >
						   评阅意见
					</p>
				</div>

				<div class="main80" align="center">
					<form:textarea id="remark" path="remark" name="py"  style="width:844px;height:93px;resize:none"
						  onkeydown='countChar("remark","numbers");' onkeyup='countChar("remark","numbers");' />
					
				</div>
				 <div id="remarkLength" style="margin: 6px; clear:both; font-size: 14px;">
                        <label style="color: green">字数至少20, 您已输入 </label><label id="numbers" style="color:red">0</label><label style="color:green"> 字</label>
                    </div>

				<div class="main2" style="padding-top:8px">
				<span style="margin-left:10px">
					系统评语模板： <select id="remarkTemplate" name="name">
						<option value="0">-请选择-</option>
						<c:forEach items="${remarkTemplate}" var="remark" varStatus="i">
							<option value="${remark.id}">${remark.keyword}</option>
						</c:forEach>
					</select>
				</span>
				<span>
					<input value="保存为模板" id="toRemarkTemplate" type="button"/>
				</span>
				</div>
				<p style="margin-left: 15px;">注：各专业应根据自己的具体情况，制定出适合本专业的毕业设计（论文）的具体要求和评分标准。</p>
				<p>
					<input type="hidden" value="${projectId}" name="projectId" id="projectId"/>
					<input name="w" id="toExcel" type="button" value="导出excel表"
						style="margin-left: 500px;"
						 />
					<!-- <input name="btn1" id="btn1" type="button" value="打印" />  -->
					<input
						name="submit1" id="save" type="button" value="提交"
						 /> <input name="submit2" id="temporary"
						type="button" value="暂存" /> <input name="btn1"
						id="cancel" type="reset" value="取消" />
				</p>
				
			</form:form>

		</div>
	</div>
	<input type="hidden" id="state" value="${reviewProject.state}" />
	<p style="color: #0000FF; padding-left: 800px;">[1]&nbsp;[2]&nbsp;[3]...下一页&nbsp;&nbsp;共有30条记录</p>
</body>
</html>